package com.lujianfei.waterpower.ui.water;

import android.os.Parcel;
import android.os.Parcelable;

import com.lujianfei.waterpower.utils.BasisTimesUtils;
import com.lujianfei.waterpower.utils.SharePreferenceUtils;
import com.orm.SugarRecord;
import com.orm.dsl.Column;
import com.orm.dsl.Ignore;
import com.orm.dsl.Table;

import java.util.Objects;

@Table(name = "WaterEntity")
public class WaterEntity extends SugarRecord implements Parcelable {

    @Column(name = "readout")
    private double readout;

    @Column(name = "unit_price")
    private double unit_price;

    @Column(name = "create_time")
    private long create_time;

    @Column(name = "update_time")
    private long update_time;

    @Column(name = "set_date")
    private long set_date;

    @Column(name = "uri_photo")
    private String uri_photo;

    @Column(name = "remark")
    private String remark;
    
    @Ignore
    private String price_amount;

    @Ignore
    private WaterEntity next;

    public WaterEntity getNext() {
        return next;
    }

    public void setNext(WaterEntity next) {
        this.next = next;
    }

    public long getSet_date() {
        return set_date;
    }

    public void setSet_date(long set_date) {
        this.set_date = set_date;
    }
    public double getReadout() {
        return readout;
    }

    public void setReadout(double readout) {
        this.readout = readout;
    }

    public double getUnit_price() {
        return unit_price;
    }

    public void setUnit_price(double unit_price) {
        this.unit_price = unit_price;
    }

    public long getCreate_time() {
        return create_time;
    }

    public void setCreate_time(long create_time) {
        this.create_time = create_time;
    }

    public long getUpdate_time() {
        return update_time;
    }

    public void setUpdate_time(long update_time) {
        this.update_time = update_time;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
    
    public String getDateStr() {
        if (0 == set_date){
            return "";
        }
        return BasisTimesUtils.getStringDateTime(set_date);
    }
    public String getPrice_amount() {
        return price_amount;
    }

    public void setPrice_amount(String price_amount) {
        this.price_amount = price_amount;
    }

    public WaterEntity(){
        unit_price = SharePreferenceUtils.getInstance().getWaterUnit();
    }
    public WaterEntity(Parcel in) {
        readout = in.readDouble();
        unit_price = in.readDouble();
        create_time = in.readLong();
        update_time = in.readLong();
        set_date = in.readLong();
        price_amount = in.readString();
        uri_photo = in.readString();
        remark = in.readString();
    }

    public String getUri_photo() {
        return uri_photo;
    }

    public void setUri_photo(String uri_photo) {
        this.uri_photo = uri_photo;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeDouble(readout);
        dest.writeDouble(unit_price);
        dest.writeLong(create_time);
        dest.writeLong(update_time);
        dest.writeLong(set_date);
        dest.writeString(price_amount);
        dest.writeString(uri_photo);
        dest.writeString(remark);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<WaterEntity> CREATOR = new Creator<WaterEntity>() {
        @Override
        public WaterEntity createFromParcel(Parcel in) {
            return new WaterEntity(in);
        }

        @Override
        public WaterEntity[] newArray(int size) {
            return new WaterEntity[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        WaterEntity that = (WaterEntity) o;
        return Double.compare(that.readout, readout) == 0 &&
                Double.compare(that.unit_price, unit_price) == 0 &&
                create_time == that.create_time &&
                update_time == that.update_time &&
                set_date == that.set_date &&
                Objects.equals(uri_photo, that.uri_photo) &&
                Objects.equals(price_amount, that.price_amount) &&
                Objects.equals(remark, that.remark);
    }

    @Override
    public int hashCode() {
        return Objects.hash(readout, unit_price, create_time, update_time, set_date, uri_photo, price_amount, remark);
    }
}
